/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package comunicacaors232;

import gnu.io.CommPortIdentifier;

import java.util.Enumeration;

/**
 *
 * @author R3oLoN
 */
public class SerialConexao {

    protected String[] portas;
    protected Enumeration listaDePortas;

    public SerialConexao() {

        listaDePortas = CommPortIdentifier.getPortIdentifiers();

    }

    public String[] ObterPortas() {

        return portas;

    }

    protected void ListarPortas() {

        int i = 0;

        portas = new String[10];

        while (listaDePortas.hasMoreElements()) {

            CommPortIdentifier ips =
                    (CommPortIdentifier) listaDePortas.nextElement();

            portas[i] = ips.getName();

            i++;

        }

    }

    public boolean PortaExiste(String COMp) {

        String temp;

        boolean e = false;

        while (listaDePortas.hasMoreElements()) {

            CommPortIdentifier ips = (CommPortIdentifier) listaDePortas.nextElement();

            temp = ips.getName();

            if (temp.equals(COMp) == true) {

                e = true;

            }

        }

        return e;

    }
}
